<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: LLg
  Date: 2022/10/3
  Time: 11:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>水果查询</title>
    <script src="js/jquery-3.6.0.js"></script>
</head>
<body>
<h1 align="center">水果详情列表</h1>
    <table border="1px" cellpadding="0" align="center">
        <tr align="center">
            <td>类别</td>
            <td>品种</td>
            <td>产地</td>
            <td>总重量(公斤)</td>
            <td>单价(元/公斤)</td>
            <td>操作</td>
        </tr>
        <c:forEach items="${list}" var="fruit">
            <tr>
                <td>${fruit.type}</td>
                <td>${fruit.breed}</td>
                <td>${fruit.area}</td>
                <td>${fruit.weight}</td>
                <td>${fruit.price}</td>
                <td><a href="FruitSelectIdServlet?fruitId=${fruit.fruitId}">详情</a> <a href="javascript:void(0)" onclick="del(${fruit.fruitId})">删除</a> </td>
            </tr>
        </c:forEach>
    </table>
<script>
    $(function (){
        $("table tr:odd").css("background-color","pink")
        $("table tr:eq(0)").css("background-color","yellow")
    })
    function del(fruitId) {
        if (confirm('确认要删除吗?')){
            $.getJSON(
                "FruitDeleteServlet",
                {fruitId:fruitId},
                function (data){
                    if (data){
                        alert('删除成功!')
                        location.reload();
                    }else {
                        alert('删除失败!')
                    }
                }
            )
        }
    }
</script>
</body>
</html>
